/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package socius.app; import java.net.MalformedURLException; import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.util.logging.Level; import java.util.logging.Logger; import socius.autenticacao.AutenticacaoRemota; import socius.autenticacao.AutenticadorUsuario; import socius.dispositivos.Servidor; import socius.thread.MantemListaComputadoresOnlineThread; import socius.util.ConfigSistema; /** * * @author Lucas Dillmann <lucas [at] dillmann.com.br> */ public class ServerBoot { public static void main(String[] args) throws Exception { // Instancia e inicializa o Servidor para // escuta e atendimento de requisições na respectiva porta ServerBoot boot = new ServerBoot(); boot.inicializarServidor(); } public void inicializarServidor() { try { // Registra com o RMI int porta = Integer.parseInt( ConfigSistema.getProperty("servidor.porta_escuta")); System.setProperty( "java.rmi.server.hostname", ConfigSistema.getProperty("cliente.ip_servidor") ); LocateRegistry.createRegistry(porta); //cria um objeto remoto Servidor servidor = new Servidor(); // Cria objeto responsável pela autenticação, o aceso ao servidor // apenas será possível se este liberar AutenticacaoRemota autenticador = new AutenticadorUsuario(servidor); // Cria URL onde o servidor irá escutar // Exemplo de saida: //localhost:443/socius StringBuilder urlRMI = new StringBuilder(); urlRMI.append("rmi://"); urlRMI.append(ConfigSistema.getProperty("servidor.ip_escuta")); urlRMI.append(":"); urlRMI.append(ConfigSistema.getProperty("servidor.porta_escuta")); urlRMI.append("/"); urlRMI.append(ConfigSistema.getProperty("servidor.nome_servico")); //setar a instancia corrente Naming.rebind(urlRMI.toString(), autenticador); // Inicia Thread que irá manter atualizada a lista de clientes online new MantemListaComputadoresOnlineThread(servidor).start(); System.out.println("Servidor inicializado. Aguardando conexões..."); } catch (RemoteException | MalformedURLException ex) { Logger.getLogger(Servidor.class.getName()).log(Level.SEVERE, null, ex); } } }